using System.Collections.Generic;
using System.Text;
using UnityEngine;

namespace Miao
{
	/// <summary>
	/// 
	/// </summary>
	public static class MeshPool
	{

		private static Dictionary<Vector2, Mesh> planes;

		private static Dictionary<Vector2, Mesh> planesFlip;

		static MeshPool()
		{
            planes = new Dictionary<Vector2, Mesh>();
			planesFlip = new Dictionary<Vector2, Mesh>();
        }

		public static Mesh GridPlane(Vector2 size)
		{
			if (!planes.TryGetValue(size, out var value))
			{
				value = MeshMakerPlanes.NewPlaneMesh(size, flipped: false, backLift: false, twist: false);
				planes.Add(size, value);
			}
			return value;
		}

		public static Mesh GridPlaneFlip(Vector2 size)
		{
			if (!planesFlip.TryGetValue(size, out var value))
			{
				value = MeshMakerPlanes.NewPlaneMesh(size, flipped: true, backLift: false, twist: false);
				planesFlip.Add(size, value);
			}
			return value;
		}

		private static Vector2 RoundedToHundredths(this Vector2 v)
		{
			return new Vector2((float)(int)(v.x * 100f) / 100f, (float)(int)(v.y * 100f) / 100f);
		}

	}
}
